﻿$(function() {
    JSUtility.param.Options["InternalType"] = "1";
    JSUtility.url = "../../Handler/AjaxHandle.ashx";
    JSUtility.param.ClassName = "OA.Bll.Project.ProjectPayBackStatisticsPresenter";
    autoResize({ dataGrid: '#Grid', callback: Initlist });
    //$('#Add').css('display', 'none');
    JSUtility.window_edit = $('#Add').window({
        iconCls: 'icon-add',
        zIndex: 1000,
        draggable: true,
        resizable: false,
        shadow: true,
        inline: true,
        modal: true,
        title: '添加项目获奖信息',
        collapsible: false,
        minimizable: false,
        maximizable: false,
        closable: true,
        width: 300,
        // height: 350,
        closed: true,
        onOpen: function() {
            $('#Add').parent().css("left", "25%");
            $('#Add').parent().next().css("left", "25%");
            $('#Add').parent().next().css("top", "25%");
            $('#Add').parent().css("top", "25%");
        }
    });
    JSUtility.window_edit_title = "项目回款统计信息";
    JSUtility.window_edit_form = $('#Add').find("form");
    // comboboxInitial();
    $('#Add').show();
    AjaxAll();
});

function comboboxInitial() {
    JSHelper.comboboxData("#PrizeLevel", "8");
}

function AjaxAll() {
    JSUtility.param.Method = "GetSearchAll";
    $.ajax({
        type: "post",
        url: JSUtility.url,
        data: $.toJSON(JSUtility.param),
        async: false,
        dataType: "json",
        success: function(data) {
            $("#SumContractAmount").html(data.SumContractAmount);
            $("#SumContractEffectiveAmount").html(data.SumContractEffectiveAmount);
            $("#SumApplyAmount").html(data.SumApplyAmount);
            $("#SumBillAmount").html(data.SumBillAmount);
            $("#SumCashAmount").html(data.SumCashAmount);
            $("#ReceivableAmount").html(data.ReceivableAmount);
            $("#AmountCashed").html(data.AmountCashed);
            $("#CashScale").html(data.CashScale);
        }
    });
}

function Initlist(size) {

    JSUtility.param.Method = "Search";
    JSUtility.grid = $('#Grid').datagrid({
        tilte: '项目回款统计信息',
        iconCls: 'icon-save',
        width: size.width - 50,
        height: size.height - 100,
        pageSize: Math.round(size.height / 25) < 0 ? 15 : Math.round(size.height / 25),
        pageList: [Math.round(size.height / 25)],
        nowrap: true,
        striped: true,
        url: JSUtility.url,
        queryParams: { "json": $.toJSON(JSUtility.param) },
        sortName: 'Id',
        sortOrder: 'desc',
        idField: 'Id',
        frozenColumns: [[{ title: '编号', field: 'Id', width: 50, sortable: true}]],
        columns: [[
                    { title: '项目编号', field: 'ProjectNum', width: 80 },
                    { title: '项目名称', field: 'ProjectName', width: 100 },
        //                    { title: '合同编号', field: 'PrizeName', width: 100 },
        //                    { title: '合同名称', field: 'PrizeTime', width: 80 },
                    {title: '合同总金额', field: 'SumContractAmount', width: 100 },
                    { title: '有效合同总额', field: 'SumContractEffectiveAmount', width: 100 },
                    { title: '申请总金额', field: 'SumApplyAmount', width: 100 },
                    { title: '收入累计金额', field: 'SumBillAmount', width: 100 },
                    { title: '现金累计回款', field: 'SumCashAmount', width: 100 },
                    { title: '应收账款', field: 'desc', width: 100, formatter: function(val, rowData, rowIndex) {

                        var data = parseFloat(rowData.SumBillAmount) - parseFloat(rowData.SumCashAmount);
                        return "<span>" + data + "</span>";

                    }
                    },
                    { title: '待回款金额', field: 'desc2', width: 100, formatter: function(val, rowData, rowIndex) {

                        var data = parseFloat(rowData.SumContractAmount) - parseFloat(rowData.SumCashAmount);
                        return "<span>" + data + "</span>";

                    }
                    },
                    { title: '已回款比例', field: 'desc3', width: 100, formatter: function(val, rowData, rowIndex) {
                        if (rowData.SumContractEffectiveAmount == 0) return "0.00%";
                        var data = parseFloat(rowData.SumCashAmount) / parseFloat(rowData.SumContractEffectiveAmount);
                        data = parseFloat(data) * 100;
                        var length = data.toString().length > 4 ? 4 : data.toString().length;
                        data = data.toString().substring(0, length) + "%";
                        //alert(data);
                        return "<span>" + data + "</span>";

                    }
                    }
                  ]],
        pagination: true,
        rownumbers: true,
        singleSelect: true,
        toolbar: [
        //                    {
        //                        text: '添加',
        //                        iconCls: 'icon-add',
        //                        handler: JSUtility.add
        //                    }, '-',
        //                    {
        //                        text: '修改',
        //                        iconCls: 'icon-edit',
        //                        handler: JSUtility.update
        //                    }, '-',
        //                    {
        //                        text: '删除',
        //                        iconCls: 'icon-remove',
        //                        handler: JSUtility.del
        //                    }, '-',
                    {
                    text: '查询',
                    iconCls: 'icon-search',
                    handler: JSUtility.search
                }
                  ]
    });
}

